import type { Status, VueComType } from './common';

export interface BaseProps {
  id: string;
  isShow: boolean;
  name: string;
  editCom: VueComType;
}
export type StringStatusArr = string[];
export type ValueStatusArr = Array<{
  value: string;
  status: string;
  [key: string]: any;
}>;
export type PicTitleDescStatusArr = Array<{
  value: string;
  picTitle: string;
  picDesc: string;
  [key: string]: any;
}>;
export type StatusArray = StringStatusArr | ValueStatusArr | PicTitleDescStatusArr;
// export type StatusArray = any[];

// status为字符串时
export interface TextProps extends BaseProps {
  status: string;
}
// status为数组时
export interface OptionsProps extends BaseProps {
  status: StatusArray;
  currentStatus: number;
}

// 公共设置项每个组件都有的设置项
export interface BaseStatus {
  title: TextProps;
  desc: TextProps;
  position: OptionsProps;
  titleSize: OptionsProps;
  descSize: OptionsProps;
  titleWeight: OptionsProps;
  descWeight: OptionsProps;
  titleItalic: OptionsProps;
  descItalic: OptionsProps;
  titleColor: TextProps;
  descColor: TextProps;
}

// 不是每个组件都有options
export interface OptionsStatusProps extends BaseStatus {
  options: OptionsProps;
}
export type ConfigKey = keyof OptionsStatusProps;
// export type key = keyof OptionsStatusProps
export interface TypeStatus extends BaseStatus {
  type: OptionsProps;
}

export function hasOptions(status: { [key: string]: TextProps | OptionsProps }) {
  return 'options' in status;
}
export function isTypeStatus(status: any) {
  return 'type' in status;
}
// 是否字符串数组
export function isStringArray(arr: StatusArray): arr is StringStatusArr {
  return Array.isArray(arr) && typeof arr[0] === 'string';
}

// 是否valueStatus数组
export function isValueStatusArray(arr: StatusArray): arr is ValueStatusArr {
  return Array.isArray(arr) && typeof arr[0] === 'object' && 'value' in arr[0] && 'status' in arr[0];
}
export function isPicTitleDescStatusArray(arr: StatusArray): arr is PicTitleDescStatusArr {
  return (
    Array.isArray(arr) && typeof arr[0] === 'object' && 'value' in arr[0] && 'picTitle' in arr[0] && 'picDesc' in arr[0]
  );
}

export type ValueIndex = { value: any; index: number; key?: string };
export type PicLink = { link: string; index: number };
export function isValueIndex(obj: object) {
  return 'value' in obj && 'index' in obj;
}
export function isPicLink(obj: object) {
  return 'link' in obj && 'index' in obj;
}

export type GetLink = (obj: PicLink) => void;

export type UpdateStatus = (configKey: string, payload?: number | string | boolean | object) => void;
